package 多线程.虚假唤醒;

import java.util.concurrent.locks.LockSupport;

/**
 *
 */
public class parkUnpark04 {
    //不需要在锁块中
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            int i = 0;
            while (true){
                System.out.println(i++);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //只能自己park自己
        //但是可以别人unpark另一个人
        //所以下边的park失效
        thread.start();
        LockSupport.park(thread);
        LockSupport.park(thread);
        LockSupport.park(thread);
        LockSupport.park(thread);
    }

}
